package com.buba.livenuniappservernew.api.coachmanagement.controller;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.buba.livenuniappservernew.api.coachmanagement.pojo.CoachManagement;
import com.buba.livenuniappservernew.api.coachmanagement.service.ICoachManagementService;
import com.buba.livenuniappservernew.common.CommonResult;
import com.buba.livenuniappservernew.utils.RedisUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 教练管理表
 前端控制器
 * </p>
 *
 * @author mading
 * @since 2024-09-04
 */
@RestController
@RequestMapping("/CoachManagementController")
@CrossOrigin
public class CoachManagementController {
    @Autowired
    private ICoachManagementService iCoachManagementService;
    @Autowired
    private RedisUtil redisUtil;

    /**
     * 查询所有教练信息
     * @param id
     * @return
     */
    @RequestMapping("/listCoachManagement")
    public CommonResult listCoachManagement(@Param("id") Integer id){
        // 判断 id 是否为 0 不为空就是根据id查询教练信息
        //获取存的第一个redis
        List<Object> list1 = redisUtil.lGet("listCoachManagement1", 0, -1);

        //获取存的第二个redis
        List<Object> list2 = redisUtil.lGet("listCoachManagement2", 0, -1);

        if (list1!=null && !list1.isEmpty()){
            return CommonResult.success(list1);
        }
        if (list2 != null && !list2.isEmpty()){
            redisUtil.lSet("listCoachManagement1",list2);
            return CommonResult.success(list2);
        }
        // 如果前面条件都不满足，调用服务获取数据
        CommonResult result = iCoachManagementService.listCoachManagement();
        return result;
    }
}
